package com.heima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heima.reggie.bean.DishFlavor;
import com.heima.reggie.mapper.DishFlavorMapper;
import com.heima.reggie.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {
    @Autowired
    private DishFlavorMapper mapper;
    /**
      * 新增
      * @param
      * @param
      * @return
      */
    @Override
    public int add(DishFlavor dishFlavor) {
        return mapper.insert(dishFlavor);
    }
/**
  * 根据菜品id删除
  * @param
  * @param
  * @return
  */
    @Override
    public int deleteByDid(long did) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId, did);
        return mapper.delete(lqw);
    }
/**
  * 根据菜品id统计口味数量
  * @param
  * @param
  * @return
  */
    @Override
    public int countByDid(long did) {
        QueryWrapper<DishFlavor> lqw = new QueryWrapper<>();
        //lqw.select("count(*) asd");
        lqw.lambda().eq(DishFlavor::getDishId, did);
        return mapper.selectCount(lqw);
    }
/**
  * 根据菜品id查询口味
  * @param
  * @param
  * @return
  */
    @Override
    public List<DishFlavor> selectByDid(long did) {
        QueryWrapper<DishFlavor> lqw = new QueryWrapper<>();
        lqw.lambda().eq(DishFlavor::getDishId, did);
        return mapper.selectList(lqw);
    }
}
